#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Node
{
    int key, val, n;
    Node *children[100];
} node[110];
int n, m, s, sum = 0;
vector<int> v;
bool cmp(Node *n1, Node *n2)
{
    return n1->val > n2->val;
}
void dfs(Node *t)
{
    if (t->n == 0)
    {
        sum += t->val;
        v.push_back(t->val);
        if (sum == s)
        {
            for (int i = 0; i < v.size(); i++)
                i == 0 ? printf("%d", v[i]) : printf(" %d", v[i]);
            printf("\n");
        }
    }
    else if (t->n != 0)
    {
        sum += t->val;
        if (sum < s)
        {
            v.push_back(t->val);
            for (int i = 0; i < t->n; i++)
                dfs(t->children[i]);
        }
        else
        {
            sum -= t->val;
            return;
        }
    }
    sum -= t->val;
    v.pop_back();
}
int main()
{
    int i, tval;
    scanf("%d%d%d", &n, &m, &s);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &tval);
        node[i].key = i;
        node[i].val = tval;
        node[i].n = 0;
    }
    int tkey, tchild, tn, tc;
    for (i = 0; i < m; i++)
    {
        scanf("%d %d", &tkey, &tn);
        node[tkey].n = tn;
        int k = 0;
        for (int j = 0; j < tn; j++)
        {
            scanf("%d", &tc);
            node[tkey].children[k++] = &node[tc];
        }
        sort(node[tkey].children, node[tkey].children + tn, cmp);
    }
    dfs(&node[0]);
    return 0;
}
